#include <iostream>
#include <vector>
using namespace std;

class App {
	int cnt = 1, leaf = 0, father = 0, vertex = 0;
	vector<int> head, next, to, maxsub, size, center;

	void addedge(int u, int v)
	{
		next[cnt] = head[u];
		to[cnt] = v;
		head[u] = cnt++;
	}

	void dfs(int u, int p)
	{
		size[u] = 1;
		maxsub[u] = 0;
		for (int e = head[u], v = to[e]; e; e = next[e], v = to[e]) {
			if (v != p) {
				dfs(v, u);
				size[u] += size[v];
				maxsub[u] = max(maxsub[u], size[v]);
			}
		}
		maxsub[u] = max(maxsub[u], vertex - size[u]);
	}

	int getcenter()
	{
		int m = 0;
		for (int i = 1; i <= vertex; i++) {
			if (maxsub[i] <= vertex >> 1) {
				center[m++] = i;
			}
		}
		return m;
	}

        void findleaf(int u, int p)
        {
                for(int e = head[u]; e; e = next[e]){
                        if(to[e] != p){
                                findleaf(to[e], u);
                                return;
                        }
                }
                leaf = u;
                father = p;
        }

    public:
	App(int n) : vertex(n), head(n + 1, 0), maxsub(head), size(head), next(n << 1, 0), to(n << 1, 0), center(2, 0)
	{
	}

	void run()
	{
		for (int i = 1, u, v; i < vertex; i++) {
			cin >> u >> v;
			addedge(u, v);
			addedge(v, u);
		}
		dfs(1, 0);
		if (getcenter() == 1) {
			int u = center[0];
			int v = to[head[u]];
			cout << u << " " << v << endl;
			cout << u << " " << v << endl;
		}else{
                        findleaf(center[0], center[1]);
                        cout << father << " " << leaf << endl;
                        cout << center[1] << " " << leaf << endl;
                }
	}
};

int main()
{
        int t;
        cin >> t;
        while(t--){
                int n;
                cin >> n;
                App app(n);
                app.run();
        }
	return 0;
}